#version 330
//#define SHOW_NORMALS

uniform vec3 u_Up;
uniform vec3 u_Down;
uniform vec3 u_topColor;
uniform vec3 u_bottomColor;

#ifdef TX_COLOR
uniform sampler2D u_Texture;
#endif

in vec3 fs_Normal;
in vec3 fs_Position;

#ifdef TX_COLOR
in vec2 fs_txCoord;
#else
in vec3 fs_Color;
#endif

out vec4 out_Color;

const float ambient_factor = .1f;

void main(void)
{
/*
	if(!gl_FrontFacing) {
		discard;
		return;
	}
*/

	vec3 light = mix(u_bottomColor, u_topColor, (.5f + .5f*dot(normalize(fs_Normal), u_Up)));
#ifdef SHOW_NORMALS
	out_Color = vec4(.5f + .5f*normalize(fs_Normal), 1.0f);
#else
#ifdef TX_COLOR
	out_Color = vec4(texture(u_Texture, fs_txCoord).rgb * ambient_factor * light, 1.0f);
#else
	out_Color = vec4(fs_Color * ambient_factor * light, 1.0f);
	//out_Color = vec3(0.0f, .5f, 0.0f);
#endif // #ifdef TX_COLOR
#endif // #ifdef SHOW_NORMALS
	
    //out_Color = vec3(max(0.0f,dot(-normalize(fs_Position.xyz),fs_Normal))*.5f + .5f);
    //out_Color = vec3(1.0f, 0.0f, 0.0f);
}
